package com.taiyi.renaissancemall.ui.main.first;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;

import androidx.constraintlayout.widget.Guideline;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.liaoinstan.springview.container.DefaultFooter;
import com.liaoinstan.springview.container.DefaultHeader;
import com.liaoinstan.springview.widget.SpringView;
import com.taiyi.renaissancemall.R;
import com.taiyi.renaissancemall.Utils.ActivityUtils;
import com.taiyi.renaissancemall.Utils.GlideOptionsManager;
import com.taiyi.renaissancemall.Utils.MyImageLoader;
import com.taiyi.renaissancemall.Utils.RoundBannerViewHolder;
import com.taiyi.renaissancemall.Utils.ScrollGridLayoutManager;
import com.taiyi.renaissancemall.Utils.ToastUtils;
import com.taiyi.renaissancemall.adapter.AdapterManager;
import com.taiyi.renaissancemall.adapter.baseadapter.CommonAdapter;
import com.taiyi.renaissancemall.adapter.baseadapter.MultiItemTypeAdapter;
import com.taiyi.renaissancemall.base.BaseFragment;
import com.taiyi.renaissancemall.bean.EmptyBean;
import com.taiyi.renaissancemall.bean.FindBrandListBean;
import com.taiyi.renaissancemall.bean.FirstBean;
import com.taiyi.renaissancemall.bean.FirstClassSwitchBean;
import com.taiyi.renaissancemall.ui.classification.goodlist.GoodListActivity;
import com.taiyi.renaissancemall.ui.main.brand.BrandListActivity;
import com.taiyi.renaissancemall.ui.main.first.goodSelect.GoodSelectActivity;
import com.taiyi.renaissancemall.ui.main.first.memberBenefits.MemberBenefitsActivity;
import com.taiyi.renaissancemall.ui.main.goodsdetail.GoodsDetailActivity;
import com.taiyi.renaissancemall.ui.main.imagegoodlist.ImageGoodsListActivity;
import com.taiyi.renaissancemall.ui.main.message.MessageActivity;
import com.taiyi.renaissancemall.ui.main.personshare.PersonShareActivity;
import com.taiyi.renaissancemall.ui.main.search.SearchActivity;
import com.taiyi.renaissancemall.ui.text_webview.TextWebViewActivity;
import com.taiyi.renaissancemall.view.CustomScrollview;
import com.taiyi.renaissancemall.view.HorizontalRecycleview;
import com.taiyi.renaissancemall.view.MyScrollView;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerListener;
import com.zhouwei.mzbanner.MZBannerView;
import com.zhouwei.mzbanner.holder.MZHolderCreator;
import com.zhouwei.mzbanner.holder.MZViewHolder;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import butterknife.BindView;
import butterknife.OnClick;

public class FirstFragment extends BaseFragment<FirstView, FirstPresent> implements FirstView, SpringView.OnFreshListener, MZBannerView.BannerPageClickListener, MZHolderCreator, OnBannerListener {

    @BindView(R.id.top)
    TextView top;
    @BindView(R.id.searchTv)
    TextView searchTv;
    @BindView(R.id.messageIv)
    ImageView messageIv;
    @BindView(R.id.carouselView)
    Banner carouselView;
    @BindView(R.id.topB)
    TextView topB;
    @BindView(R.id.springView)
    SpringView springView;
    @BindView(R.id.horizontalRecyclerView)
    HorizontalRecycleview horizontalRecyclerView;
    @BindView(R.id.horizontalScrollView)
    RelativeLayout horizontalScrollView;
    @BindView(R.id.announcementBackground)
    TextView announcementBackground;
    @BindView(R.id.brandStoryTv)
    TextView brandStoryTv;
    @BindView(R.id.brandStoryRecyclerView)
    HorizontalRecycleview brandStoryRecyclerView;
    @BindView(R.id.nestedScrollView)
    MyScrollView nestedScrollView;
    //    @BindView(R.id.brandStoryHorizontalScrollView)
//    HorizontalScrollView brandStoryHorizontalScrollView;
    @BindView(R.id.guideLine)
    Guideline guideLine;
    @BindView(R.id.brandStoryA)
    TextView brandStoryA;
    @BindView(R.id.brandStoryB)
    TextView brandStoryB;
    @BindView(R.id.brandLeftTitleTv)
    TextView brandLeftTitleTv;
    @BindView(R.id.brandLeftildTitleTv)
    TextView brandLeftildTitleTv;
    @BindView(R.id.brandRightTitleTv)
    TextView brandRightTitleTv;
    @BindView(R.id.brandRightChildTitleTv)
    TextView brandRightChildTitleTv;
    @BindView(R.id.limitedTime)
    TextView limitedTime;
    @BindView(R.id.limitedTimeTv)
    TextView limitedTimeTv;
    @BindView(R.id.dayTop)
    TextView dayTop;
    @BindView(R.id.mondayTv)
    TextView mondayTv;
    @BindView(R.id.tuesdayTv)
    TextView tuesdayTv;
    @BindView(R.id.wednesdayTv)
    TextView wednesdayTv;
    @BindView(R.id.thursdayTv)
    TextView thursdayTv;
    @BindView(R.id.fridayTv)
    TextView fridayTv;
    @BindView(R.id.saturdayTv)
    TextView saturdayTv;
    @BindView(R.id.sundayTv)
    TextView sundayTv;
    @BindView(R.id.limitedTimeIv)
    ImageView limitedTimeIv;
    @BindView(R.id.playVideoIv)
    ImageView playVideoIv;
    @BindView(R.id.limitedTimeTitleTv)
    TextView limitedTimeTitleTv;
    @BindView(R.id.snapUpNowTv)
    TextView snapUpNowTv;
    @BindView(R.id.limitedTimePriceTv)
    TextView limitedTimePriceTv;
    @BindView(R.id.limitedTimeSourcePriceTv)
    TextView limitedTimeSourcePriceTv;
    @BindView(R.id.limitedTimeLeft)
    TextView limitedTimeLeft;
    @BindView(R.id.limitedTimeRight)
    TextView limitedTimeRight;
    @BindView(R.id.limitedTimeLeftTitleTv)
    TextView limitedTimeLeftTitleTv;
    @BindView(R.id.limitedTimeLeftChildTitleTv)
    TextView limitedTimeLeftChildTitleTv;
    @BindView(R.id.limitedTimeRightTitleTv)
    TextView limitedTimeRightTitleTv;
    @BindView(R.id.limitedTimeRightChildTitleTv)
    TextView limitedTimeRightChildTitleTv;
    @BindView(R.id.newDailyTitleRecyclerView)
    RecyclerView newDailyTitleRecyclerView;
    @BindView(R.id.newDailyIv)
    ImageView newDailyIv;
    @BindView(R.id.newDailyRecyclerView)
    RecyclerView newDailyRecyclerView;
    @BindView(R.id.firstBottomTitleRecyclerView)
    RecyclerView firstBottomTitleRecyclerView;
    @BindView(R.id.firstBottomIv)
    ImageView firstBottomIv;
    @BindView(R.id.firstBottomIconRecyclerView)
    HorizontalRecycleview firstBottomIconRecyclerView;
    @BindView(R.id.firstBottomRecyclerView)
    RecyclerView firstBottomRecyclerView;
    @BindView(R.id.brandStoreProductRecyclerView)
    RecyclerView brandStoreProductRecyclerView;
    @BindView(R.id.limitedTimeRecyclerView)
    RecyclerView limitedTimeRecyclerView;
    @BindView(R.id.viewFlipper)
    ViewFlipper viewFlipper;
    @BindView(R.id.first_img)
    ImageView firstImg;
    private String commodityid;//限时抢购模块商品id
    private List<FirstBean.Lable1Bean.LableonelistBean> lableonelist;
    private int threeClassLabelId;
    private String threeClassLabelName;
    private String bottomOneId = "";
    private String bottomThreeId = "";
    private String bottomThreeTitle = "";
    private List<FirstBean.CarousellistBean> carousellist;


    @Override
    public FirstPresent initPresenter() {
        return new FirstPresent();
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        springView.setHeader(new DefaultHeader(getContext()));
//        springView.setFooter(new DefaultFooter(getContext()));
        springView.setGive(SpringView.Give.BOTH);
        springView.setType(SpringView.Type.FOLLOW);

        springView.setListener(this);

        firstBottomIconRecyclerView.setHasFixedSize(true);
        newDailyTitleRecyclerView.setHasFixedSize(true);
        firstBottomTitleRecyclerView.setHasFixedSize(true);
        limitedTimeRecyclerView.setHasFixedSize(true);
        firstBottomRecyclerView.setHasFixedSize(true);
        newDailyRecyclerView.setHasFixedSize(true);
        brandStoreProductRecyclerView.setHasFixedSize(true);
        brandStoryRecyclerView.setHasFixedSize(true);

        limitedTimeRecyclerView.setNestedScrollingEnabled(false);
        firstBottomIconRecyclerView.setNestedScrollingEnabled(false);
        newDailyTitleRecyclerView.setNestedScrollingEnabled(false);
        firstBottomTitleRecyclerView.setNestedScrollingEnabled(false);
        firstBottomRecyclerView.setNestedScrollingEnabled(false);
        newDailyRecyclerView.setNestedScrollingEnabled(false);
        brandStoreProductRecyclerView.setNestedScrollingEnabled(false);
        brandStoryRecyclerView.setNestedScrollingEnabled(false);

        firstBottomIconRecyclerView.setFocusable(false);
        newDailyTitleRecyclerView.setFocusable(false);
        limitedTimeRecyclerView.setFocusable(false);
        firstBottomTitleRecyclerView.setFocusable(false);
        firstBottomRecyclerView.setFocusable(false);
        newDailyRecyclerView.setFocusable(false);
        brandStoreProductRecyclerView.setFocusable(false);
        brandStoryRecyclerView.setFocusable(false);


        showProgress();
        presenter.getData();
        presenter.getHotSearchContent();
        presenter.getTopLabel();
    }


    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        mImmersionBar.titleBar(top).statusBarDarkFont(false, 0f).init();
    }

    @Override
    protected void initData() {

    }

    @Override
    public void initEvent() {

    }


    private String selectDay = "";

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.first_fragment_layout;
    }

    @OnClick({R.id.top, R.id.searchTv, R.id.twoBottomSeeMoreTv, R.id.bottomSeeMoreTv, R.id.messageIv,
            R.id.mondayTv, R.id.tuesdayTv, R.id.wednesdayTv, R.id.thursdayTv,
            R.id.fridayTv, R.id.saturdayTv, R.id.sundayTv, R.id.newDailyIv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.top:
                break;
            case R.id.searchTv:
                Intent intent = new Intent();
                intent.setClass(getContext(), SearchActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getContext().startActivity(intent);
//                ActivityUtils.next(getActivity(), SearchActivity.class);
                break;
            case R.id.bottomSeeMoreTv:
                Intent intent2 = new Intent(getContext(), GoodListActivity.class);
                intent2.putExtra("next_class_2_id", bottomThreeId);
                intent2.putExtra("labelId", "");
                intent2.putExtra("categoryid", "");
                intent2.putExtra("next_class_2_name", bottomThreeTitle);
                startActivity(intent2);
                break;
            case R.id.messageIv:
                startActivity(new Intent(getContext(), MessageActivity.class));
                break;

            case R.id.mondayTv:
                updateDate();
                mondayTv.setSelected(true);
                updateDateState("星期一");
                selectDay = "星期一";
                break;
            case R.id.tuesdayTv:
                updateDate();
                tuesdayTv.setSelected(true);
                updateDateState("星期二");
                selectDay = "星期二";
                break;
            case R.id.wednesdayTv:
                updateDate();
                wednesdayTv.setSelected(true);
                updateDateState("星期三");
                selectDay = "星期三";
                break;
            case R.id.thursdayTv:
                updateDate();
                thursdayTv.setSelected(true);
                updateDateState("星期四");
                selectDay = "星期四";
                break;
            case R.id.fridayTv:
                updateDate();
                fridayTv.setSelected(true);
                updateDateState("星期五");
                selectDay = "星期五";
                break;
            case R.id.saturdayTv:
                updateDate();
                saturdayTv.setSelected(true);
                updateDateState("星期六");
                selectDay = "星期六";
                break;
            case R.id.sundayTv:
                updateDate();
                sundayTv.setSelected(true);
                updateDateState("星期日");
                selectDay = "星期日";
                break;
            case R.id.newDailyIv:
            case R.id.twoBottomSeeMoreTv:
                Intent intent1 = new Intent(getContext(), GoodListActivity.class);
                intent1.putExtra("next_class_2_id", "");
                intent1.putExtra("labelId", threeClassLabelId + "");
                intent1.putExtra("categoryid", "");
                Log.i("labelId", "-----" + threeClassLabelId);
                intent1.putExtra("next_class_2_name", threeClassLabelName);
                startActivity(intent1);
                break;

        }
    }

    private void updateDate() {
        mondayTv.setSelected(false);
        tuesdayTv.setSelected(false);
        wednesdayTv.setSelected(false);
        thursdayTv.setSelected(false);
        fridayTv.setSelected(false);
        saturdayTv.setSelected(false);
        sundayTv.setSelected(false);
    }

    @Override
    public void onSuccess(FirstBean firstBean) {
        hideProgress();
        springView.onFinishFreshAndLoad();
        Log.i("dsdasdasdad", "-----" + firstBean.getDangrizhou());
        carousellist = firstBean.getCarousellist();
        initBanner(carousellist);//轮播
        initNotice(firstBean.getNoticelist());//公告
        initBrandStore(firstBean.getBrandlist());
        initBrandProductList(firstBean.getCate1list());
        initClassThree(firstBean.getLable4());
        initType(firstBean.getLablelistzong());//头部跳页按钮选项
        initClassFour(firstBean.getClassindex());//首页底部
        initSnappedUp(firstBean.getLable1(), firstBean.getDangrizhou());//限时抢购
        initLimit(firstBean.getCate2list());

    }

    private void initLimit(List<FirstBean.Cate2listBean> cate2list) {
        ScrollGridLayoutManager scrollGridLayoutManager = new ScrollGridLayoutManager(getContext(), 2) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        limitedTimeRecyclerView.setLayoutManager(scrollGridLayoutManager);
        CommonAdapter limitProductListAdapter = AdapterManager.getLimitProductListAdapter(getContext().getApplicationContext(), cate2list);
        limitedTimeRecyclerView.setAdapter(limitProductListAdapter);
        limitProductListAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                Intent intent = new Intent(getContext(), GoodListActivity.class);
                intent.putExtra("next_class_2_id", "");
                intent.putExtra("categoryid", cate2list.get(position).getCategoryid() + "");
                Log.i("sssssssss", "-----" + cate2list.get(position).getCategoryid());
                intent.putExtra("labelId", "");
                intent.putExtra("next_class_2_name", cate2list.get(position).getCategoryname());
                startActivity(intent);
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });

    }


    private void initSnappedUp(FirstBean.Lable1Bean lable1, String dangrizhou) {
        selectDay = dangrizhou;
        if ("星期一".equals(dangrizhou)) {
            mondayTv.setSelected(true);
        } else if ("星期二".equals(dangrizhou)) {
            tuesdayTv.setSelected(true);
        } else if ("星期三".equals(dangrizhou)) {
            wednesdayTv.setSelected(true);
        } else if ("星期四".equals(dangrizhou)) {
            thursdayTv.setSelected(true);
        } else if ("星期五".equals(dangrizhou)) {
            fridayTv.setSelected(true);
        } else if ("星期六".equals(dangrizhou)) {
            saturdayTv.setSelected(true);
        } else if ("星期日".equals(dangrizhou)) {
            sundayTv.setSelected(true);
        }
        limitedTimeTv.setText(lable1.getTimestr());
        lableonelist = lable1.getLableonelist();
        updateDateState(dangrizhou);

        limitedTimeIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!selectDay.equals(dangrizhou)) {
                    ToastUtils.showShortToast("请" + selectDay + "0时以后抢购");
                    return;
                }

                Bundle bundle = new Bundle();
                bundle.putString("commodityId", commodityid);
                ActivityUtils.next(getActivity(), GoodsDetailActivity.class, bundle);
            }
        });
    }

    private void updateDateState(String dangrizhou) {
        for (FirstBean.Lable1Bean.LableonelistBean lableonelistBean : lableonelist) {
            if (lableonelistBean.getDate().equals(dangrizhou)) {
                Glide.with(getContext()).load(lableonelistBean.getQiangurl()).into(limitedTimeIv);
//                limitedTimeTitleTv.setText(lableonelistBean.getLableidname() + lableonelistBean.getName());
                limitedTimeTitleTv.setText(lableonelistBean.getName());
                limitedTimePriceTv.setText("￥" + lableonelistBean.getPrice());
                limitedTimeSourcePriceTv.setText("￥" + lableonelistBean.getSanfprice());
                limitedTimeSourcePriceTv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                commodityid = lableonelistBean.getCommodityid();
                break;
            }
        }
    }

    private void initType(List<FirstBean.LablelistzongBean> lablelistzong) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        horizontalRecyclerView.setLayoutManager(linearLayoutManager);
        CommonAdapter firstTypeAdapter = AdapterManager.getFirstTypeAdapter(getContext(), lablelistzong);
        horizontalRecyclerView.setAdapter(firstTypeAdapter);
        firstTypeAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                String labletype = lablelistzong.get(position).getLabletype();
                String memberBenefitsIcon = lablelistzong.get(position).getIntroimg();
                if ("1".equals(labletype)) {//1跳商品分类界面2根据文字跳转
                    String lablename = lablelistzong.get(position).getLablename();
                    if (getString(R.string.goodSelect).equals(lablename)) {
                        startActivity(new Intent(getContext(), GoodSelectActivity.class));
                    } else {
                        //跳转分类商品列表
                        Intent intent = new Intent(getContext(), ImageGoodsListActivity.class);
                        intent.putExtra("labelId", String.valueOf(lablelistzong.get(position).getLableid()));
                        intent.putExtra("labelName", lablelistzong.get(position).getLablename());
                        startActivity(intent);
                    }
                } else {
                    String lablename = lablelistzong.get(position).getLablename();
                    if (getString(R.string.creditRecharge).equals(lablename)) {
//                        startActivity(new Intent(getContext(), RechargeActivity.class));
                        ToastUtils.showShortToast("暂未开放");
                    } else if (getString(R.string.personShare).equals(lablename)) {
                        startActivity(new Intent(getContext(), PersonShareActivity.class));
                    } else if (getString(R.string.memberBenefits).equals(lablename)) {
                        Intent intent = new Intent(getContext(), MemberBenefitsActivity.class);
                        intent.putExtra("introimg", memberBenefitsIcon);
                        startActivity(intent);
                    } else if ("限时抢购".equals(lablename)) {
                        nestedScrollView.smoothScrollTo(0, limitedTime.getTop());
                    } else if (getString(R.string.goodSelect).equals(lablename)) {
                        startActivity(new Intent(getContext(), GoodSelectActivity.class));
                    }
                }
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
    }

    private boolean isUpdate;

    private int selectThreeClassPosition = 0;

    private void initClassFour(FirstBean.ClassindexBean classindex) {
        List<FirstBean.ClassindexBean.Classindex1Bean> classindex1 = classindex.getClassindex1();//头部标题栏
        classindex1.get(0).setSelect(true);
        Glide.with(getContext()).load(classindex1.get(0).getImgurl()).into(firstBottomIv);
//        Glide.with(getContext()).load(classindex1.get(0).getImgurl()).apply(GlideOptionsManager.getInstance()).into(firstBottomIv);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        linearLayoutManager.setSmoothScrollbarEnabled(true);
        linearLayoutManager.setAutoMeasureEnabled(true);
        firstBottomTitleRecyclerView.setLayoutManager(linearLayoutManager);
        CommonAdapter firstBottomTitleAdapter = AdapterManager.getFirstBottomTitleAdapter(getContext(), classindex1);
        firstBottomTitleRecyclerView.setAdapter(firstBottomTitleAdapter);
//...

        if (classindex1 != null && classindex1.size() > 0) {
            bottomOneId = classindex1.get(0).getClassificationid();
        }

        firstBottomTitleAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                isUpdate = true;
                bottomOneId = classindex1.get(position).getClassificationid();
                bottomThreeId = "";
                selectThreeClassPosition = 0;
                Glide.with(getContext()).load(classindex1.get(position).getImgurl()).into(firstBottomIv);
                for (int i = 0; i < classindex1.size(); i++) {
                    if (i == position) {
                        classindex1.get(i).setSelect(true);
                    } else
                        classindex1.get(i).setSelect(false);
                }
                firstBottomTitleAdapter.notifyDataSetChanged();
                showProgress();
                presenter.getBottomThreeClass();
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });

        List<FirstBean.ClassindexBean.ClasscomlistBean> classcomlist = classindex.getClasscomlist();//商品列表
        ScrollGridLayoutManager scrollGridLayoutManager = new ScrollGridLayoutManager(getContext(), 2);
        scrollGridLayoutManager.setAutoMeasureEnabled(true);
        scrollGridLayoutManager.setSmoothScrollbarEnabled(true);
        firstBottomRecyclerView.setLayoutManager(scrollGridLayoutManager);
        CommonAdapter firstBottomClassProductAdapter = AdapterManager.getFirstBottomClassProductAdapter(getContext(), classcomlist);
        firstBottomRecyclerView.setAdapter(firstBottomClassProductAdapter);


        List<FirstBean.ClassindexBean.Classindex3Bean> classindex3 = classindex.getClassindex3();
        LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(getContext()) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        linearLayoutManager1.setAutoMeasureEnabled(true);
        linearLayoutManager1.setSmoothScrollbarEnabled(true);
        linearLayoutManager1.setOrientation(RecyclerView.HORIZONTAL);

        firstBottomIconRecyclerView.setLayoutManager(linearLayoutManager1);
        classindex3.get(selectThreeClassPosition).setSelected(true);
        CommonAdapter firstBottomIconAdapter = AdapterManager.getFirstBottomIconAdapter(getContext(), classindex3);
        firstBottomIconRecyclerView.setAdapter(firstBottomIconAdapter);

        firstBottomIconAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                isUpdate = false;
                bottomThreeId = classindex3.get(position).getClassificationid();
                bottomThreeTitle = classindex3.get(position).getName();
                selectThreeClassPosition = position;
                for (int i = 0; i < classindex3.size(); i++) {
                    if (i == position) {
                        classindex3.get(i).setSelected(true);
                    } else {
                        classindex3.get(i).setSelected(false);
                    }
                }
                firstBottomIconAdapter.notifyDataSetChanged();
                showProgress();
                presenter.getBottomThreeClass();
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });

        if (classindex3 != null && classindex3.size() > 0) {
            bottomThreeId = classindex3.get(0).getClassificationid();
            bottomThreeTitle = classindex3.get(0).getName();
        }

    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            mImmersionBar.titleBar(top).statusBarDarkFont(false, 0f).init();
        }
    }

    private void initClassThree(FirstBean.Lable4Bean firstBeanLable4) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        linearLayoutManager.setAutoMeasureEnabled(true);
        linearLayoutManager.setSmoothScrollbarEnabled(true);
        newDailyTitleRecyclerView.setLayoutManager(linearLayoutManager);
        List<FirstBean.Lable4Bean.LablelistBean> lablelist = firstBeanLable4.getLablelist();
        List<FirstBean.Lable4Bean.LablecomlistBean> lablecomlist = firstBeanLable4.getLablecomlist();
        lablelist.get(0).setSelect(true);
        threeClassLabelId = lablelist.get(0).getLableid();
        threeClassLabelName = lablelist.get(0).getLablename();
        CommonAdapter firstThreeClassAdapter = AdapterManager.getFirstThreeClassAdapter(getContext(), lablelist);
        newDailyTitleRecyclerView.setAdapter(firstThreeClassAdapter);
        firstThreeClassAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                threeClassLabelId = lablelist.get(position).getLableid();
                threeClassLabelName = lablelist.get(position).getLablename();
                Glide.with(getContext()).load(lablelist.get(position).getIndexintroimg()).into(newDailyIv);
                for (int i = 0; i < lablelist.size(); i++) {
                    if (i == position) {
                        lablelist.get(i).setSelect(true);
                    } else
                        lablelist.get(i).setSelect(false);
                }
                firstThreeClassAdapter.notifyDataSetChanged();
                showProgress();
                presenter.getClassSwitch(threeClassLabelId);
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
        Glide.with(getContext()).load(lablelist.get(0).getIndexintroimg()).into(newDailyIv);
        ScrollGridLayoutManager scrollGridLayoutManager = new ScrollGridLayoutManager(getContext(), 2);
        scrollGridLayoutManager.setAutoMeasureEnabled(true);
        scrollGridLayoutManager.setSmoothScrollbarEnabled(true);
        newDailyRecyclerView.setLayoutManager(scrollGridLayoutManager);
        CommonAdapter firstThreeClassProductAdapter = AdapterManager.getFirstThreeClassProductAdapter(getContext(), lablecomlist);
        newDailyRecyclerView.setAdapter(firstThreeClassProductAdapter);
        firstThreeClassProductAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                Intent intent = new Intent(getContext(), GoodsDetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("commodityId", lablecomlist.get(position).getCommodityid());
                intent.putExtras(bundle);
                startActivity(intent);
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
    }

    private void initBrandStore(List<FirstBean.BrandlistBean> cate1list) {//初始化品牌故事馆
        if (cate1list != null && cate1list.size() > 0) {
            Log.i("cate1list", "----" + cate1list.size());
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext().getApplicationContext(), RecyclerView.HORIZONTAL, false) {
                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            };
//            linearLayoutManager.setOrientation(RecyclerView.HORIZONTAL);
            brandStoryRecyclerView.setLayoutManager(linearLayoutManager);
            CommonAdapter firstBrandImgAdapter = AdapterManager.getFirstBrandImgAdapter(getContext(), cate1list);
            brandStoryRecyclerView.setAdapter(firstBrandImgAdapter);

        }
    }

    private void initBrandProductList(List<FirstBean.Cate1listBean> comlist) {//初始化品牌故事馆商品列表
        if (comlist != null && comlist.size() > 0) {
            brandStoreProductRecyclerView.setLayoutManager(new ScrollGridLayoutManager(getContext(), 2));
            CommonAdapter firstBrandProductAdapter = AdapterManager.getFirstBrandProductAdapter(getContext(), comlist);
            brandStoreProductRecyclerView.setAdapter(firstBrandProductAdapter);
        }
    }

    private void initNotice(List<FirstBean.NoticelistBean> noticelist) {//初始化公告
        for (int i = 0; i < noticelist.size(); i++) {
            View view = LayoutInflater.from(getContext()).inflate(R.layout.first_notice_item_layout, null);
            TextView tv = view.findViewById(R.id.tv);
            tv.setText(noticelist.get(i).getContent());
            viewFlipper.addView(view);
        }
    }

    List<String> imgList = new ArrayList<>();

    private void initBanner(List<FirstBean.CarousellistBean> carousellist) {//初始化轮播图
//        carouselView.setIndicatorAlign(MZBannerView.IndicatorAlign.LEFT);
        imgList.clear();
        carouselView.setImageLoader(new MyImageLoader());
        for (int i = 0; i < carousellist.size(); i++) {
            imgList.add(carousellist.get(i).getImgurl());
        }
        carouselView.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        carouselView.setIndicatorGravity(BannerConfig.LEFT);
        carouselView.setDelayTime(2000);
        carouselView.setOnBannerListener(this);
        carouselView.setImages(imgList);
        carouselView.start();


//        carouselView.setBannerPageClickListener(this);
//
//        carouselView.setPages(imgList, this);
////
////        carouselView.setPages(imgList, new MZHolderCreator<RoundBannerViewHolder>() {
////
////            @Override
////            public RoundBannerViewHolder createViewHolder() {
////                return new RoundBannerViewHolder();
////            }
////        });
//        carouselView.start();

    }

    @Override
    public void onFailure(String msg) {
        hideProgress();
        toast(msg);
    }

    @Override
    public void getClassSwitchSuccess(FirstClassSwitchBean firstClassSwitchBean) {
        hideProgress();
        List<FirstClassSwitchBean.LablecomlistBean> lablecomlist = firstClassSwitchBean.getLablecomlist();
//        if (lablecomlist.size() > 0)
//            Glide.with(getContext()).load(lablecomlist.get(0).getIntroimg()).into(newDailyIv);
        newDailyRecyclerView.setLayoutManager(new ScrollGridLayoutManager(getContext(), 2));
        CommonAdapter firstThreeClassProductAdapter = AdapterManager.getNewFirstThreeClassProductAdapter(getContext(), lablecomlist);
        newDailyRecyclerView.setAdapter(firstThreeClassProductAdapter);
        firstThreeClassProductAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                Intent intent = new Intent(getContext(), GoodsDetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("commodityId", lablecomlist.get(position).getCommodityid());
                intent.putExtras(bundle);
                startActivity(intent);
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
    }

    @Override
    public void getClassSwitchFailure(String msg) {
        hideProgress();
        toast(msg);
    }

    @Override
    public String getOneTypeId() {
        return bottomOneId;
    }

    @Override
    public String getThreeTypeId() {
        return bottomThreeId;
    }

    @Override
    public void getClassSuccess(FirstBean firstBean) {
        hideProgress();
        FirstBean.ClassindexBean classindex = firstBean.getClassindex();
        List<FirstBean.ClassindexBean.ClasscomlistBean> classcomlist = classindex.getClasscomlist();//商品列表
        ScrollGridLayoutManager scrollGridLayoutManager = new ScrollGridLayoutManager(getContext(), 2);
        scrollGridLayoutManager.setAutoMeasureEnabled(true);
        scrollGridLayoutManager.setSmoothScrollbarEnabled(true);
        firstBottomRecyclerView.setLayoutManager(scrollGridLayoutManager);
        CommonAdapter firstBottomClassProductAdapter = AdapterManager.getFirstBottomClassProductAdapter(getContext(), classcomlist);
        firstBottomRecyclerView.setAdapter(firstBottomClassProductAdapter);

        if (isUpdate) {
            List<FirstBean.ClassindexBean.Classindex3Bean> classindex3 = classindex.getClassindex3();
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext()) {
                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            };
            linearLayoutManager.setOrientation(RecyclerView.HORIZONTAL);
            firstBottomIconRecyclerView.setLayoutManager(linearLayoutManager);

            classindex3.get(selectThreeClassPosition).setSelected(true);
            CommonAdapter firstBottomIconAdapter = AdapterManager.getFirstBottomIconAdapter(getContext(), classindex3);
            firstBottomIconRecyclerView.setAdapter(firstBottomIconAdapter);
            firstBottomIconAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                    selectThreeClassPosition = position;
                    bottomThreeId = classindex3.get(position).getClassificationid();
                    bottomThreeTitle = classindex3.get(position).getName();
                    for (int i = 0; i < classindex3.size(); i++) {
                        if (i == position) {
                            classindex3.get(i).setSelected(true);
                        } else {
                            classindex3.get(i).setSelected(false);
                        }
                    }
                    ((DefaultItemAnimator) firstBottomIconRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
                    firstBottomIconAdapter.notifyItemRangeChanged(0, classindex3.size() - 1);
                    showProgress();
                    presenter.getBottomThreeClass();
                }

                @Override
                public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                    return false;
                }
            });
        }

    }

    @Override
    public void getClassFailuew(String msg) {
        hideProgress();
        toast(msg);
    }


    @Override
    public void getSearchContentSuccess(FindBrandListBean findBrandListBean) {
        hideProgress();
        String soutext = findBrandListBean.soutext;
        searchTv.setText(soutext);
    }

    @Override
    public void getSearchContentFailure(String msg) {
        hideProgress();
        toast(msg);
    }

    @Override
    public void getTopLabelSuccess(EmptyBean emptyBean) {
        hideProgress();
        Glide.with(getActivity()).load(emptyBean.getImgUrl()).into(firstImg);
    }

    @Override
    public void getTopLabelFailure(String msg) {
        hideProgress();
        toast(msg);
    }

    @Override
    public void onRefresh() {
        showProgress();
        presenter.getData();
    }

    @Override
    public void onLoadmore() {

    }

    @Override
    public void onPageClick(View view, int position) {
        if (carousellist.get(position).getApptype().equals("1")) {//1商品跳转2url跳转
            String hrefid = carousellist.get(position).getHrefid();
            Bundle bundle = new Bundle();
            bundle.putString("commodityId", hrefid);
            ActivityUtils.next(getActivity(), GoodsDetailActivity.class, bundle);
        } else {
            ToastUtils.showShortToast("暂不支持");
        }
    }

    @Override
    public MZViewHolder createViewHolder() {
        return new RoundBannerViewHolder();
    }

    @Override
    public void OnBannerClick(int position) {
        if (carousellist.get(position).getApptype().equals("1")) {//1商品跳转2url跳转
            String hrefid = carousellist.get(position).getHrefid();
            Bundle bundle = new Bundle();
            bundle.putString("commodityId", hrefid);
            ActivityUtils.next(getActivity(), GoodsDetailActivity.class, bundle);
        } else if (carousellist.get(position).getApptype().equals("3")) {
            String brandid = carousellist.get(position).getHrefid();
            //跳转品牌列表
            Intent intent = new Intent(getContext(), BrandListActivity.class);
            intent.putExtra("brandId", brandid);
//            intent.putExtra("brandName", o.getBrandname());
            startActivity(intent);
        } else {
            if (TextUtils.isEmpty(carousellist.get(position).getHref())) {
                ToastUtils.showShortToast("未找到链接");
                return;
            }
            Intent intent = new Intent(getContext(), TextWebViewActivity.class);
            intent.putExtra("url", carousellist.get(position).getHref());
            Log.i("sssssaaaaa", "------" + carousellist.get(position).getImgurl());
//            intent.putExtra("brandName", o.getBrandname());
            startActivity(intent);
//            ToastUtils.showShortToast("暂不支持");
        }
    }
}
